package com.mspbots.core.teams;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mspbots.core.AbstractBaseController;
import com.mspbots.core.teams.model.TeamsUser;
import com.mspbots.core.teams.service.TeamsUserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author billb
 */
@RestController
@RequestMapping("/teams/user")
public class TeamsUserController extends AbstractBaseController<TeamsUser, TeamsUserService> {

    @GetMapping(path = "/by-user-id/{teamsUserId}")
    public Callable selectByTeamsUserId(@PathVariable String teamsUserId) {
        return () -> service.selectByTeamsUserId(teamsUserId);
    }

    @GetMapping(path = "/{tenantId}")
    public Callable selectAllByTenantId(@PathVariable long tenantId) {
        return () -> service.selectAllByTenantId(tenantId);
    }

    @GetMapping(path = "/count/{tenantId}")
    public Callable selectCountByTenantId(@PathVariable long tenantId) {
        QueryWrapper<TeamsUser> query = new QueryWrapper<TeamsUser>();
        query.eq("tenant_id", tenantId);
        return () -> service.count(query);
    }

    @PostMapping("/add-batch/{tenantId}")
    public Callable addBatch(@PathVariable Long tenantId, @RequestBody List<TeamsUser> users) {
        return () -> service.addBatch(tenantId, users);
    }

    @GetMapping(path = "/auto-mapping/{tenantId}")
    public Callable autoMapping(@PathVariable Long tenantId) {
        return () -> service.autoMapping(tenantId);
    }

    @GetMapping("/findAdminByTenantId/{tenantId}")
    public Callable findAdminByTenantId(@PathVariable long tenantId) {
        return () -> service.findAdminByTenantId(tenantId);
    }
}
